import { Browser } from './core.js'

const browser = new Browser()

export default {
  init () {
    browser.init()
  },
  defineBack (callback) {
    return browser.define('back', callback)
  },
  defineOnBarCodeRead (callback) {
    return browser.define('onBarCodeRead', callback)
  },
  setAlias (alias, callback) {
    browser.post({ name: 'SetAlias', payload: alias, callback })
  },
  setTags (tags, callback) {
    browser.post({ name: 'SetTags', payload: tags, callback })
  },
  clearCookie () {
    browser.post({ name: 'ClearCookie' })
  },
  playVideo (url) {
    browser.post({ name: 'PlayVideo', payload: url})
  },
  configNet () {
    browser.post({ name: 'ConfigNet' })
  },
  openCamera (uploadServer, callback) {
    browser.post({ name: 'openCamera', payload: uploadServer, callback })
  },
  openVideo (uploadServer, callback) {
    browser.post({ name: 'openVideo', payload: uploadServer, callback })
  },
  openAudio (uploadServer, callback) {
    browser.post({ name: 'openAudio', payload: uploadServer, callback })
  },
  openFile (params, callback) {
    browser.post({ name: 'openFile', payload: params, callback })
  },
  onImageView (images) {
    browser.post({ name: 'imageView', payload: images })
  },
  onDocView (file) {
    browser.post({ name: 'docView', payload: file })
  },
  console(target) {
    browser.post({ name: 'console', payload: target })
  },
  openScanner() {
    browser.post({ name: 'openScanner', payload: {} })
  },
  lockToLandscape () {
    browser.post({ name: 'lockToLandscape', payload: {} })
  },
  lockToPortrait () {
    browser.post({ name: 'lockToPortrait', payload: {} })
  },
  startRecording () {
    browser.post({ name: 'startRecording', payload: {} })
  },
  endRecording (voiceServer, callback) {
    browser.post({ name: 'endRecording', payload: { voiceServer }, callback })
  },
  getApkVersion (params, callback) {
    browser.post({ name: 'getApkVersion', payload: {}, callback })
  },
  updateApk (apkPath) {
    browser.post({ name: 'updateApk', payload: { apkPath } })
  },
  checkStoragePermission ({}, callback) {
    browser.post({ name: 'checkStoragePermission', payload: {}, callback })
  }
}
